package main

import (
	"fmt"
	"gitee.com/lanfengye2002/base"
	"os"
	"strings"
)

type folder struct {
	Source string //来源
	Goal string //目的
}

type folderSlice []folder

var Suffixs=make(map[string]bool,0)
var Folders folderSlice

type config struct {
	Config struct{
		Time int //扫描间隔 单位秒 默认60
		Suffix string //需要扫描的文件后缀，多个用,间隔
		Folders string //文件夹设置，多个用,分隔，结尾不带,。格式为源文件夹=目的文件夹
	}
}

var Config=newConfig()

//初始化配置文件
func init(){
	Folders=make([]folder,0)
	err:=base.NewConfig(Config,"scanConfig.ini")
	if err!=nil{
		fmt.Println("配置文件夹读取错误：",err)
		os.Exit(0)
	}

	a:=strings.Split(Config.Config.Suffix,",")
	for _,v:=range a{
		Suffixs[v]=true
	}

	b:=strings.Split(Config.Config.Folders,",")
	for _,v:=range b{
		n:=strings.Split(v,"->")
		if len(n)>=2{
			Folders=append(Folders,folder{Source: strings.ReplaceAll(n[0],"//","\\"),Goal: strings.ReplaceAll(n[1],"//","\\")})
		}
	}
}

func newConfig() *config{
	return &config{
		Config: struct {
			Time    int
			Suffix  string
			Folders string
		}{Time: 60, Suffix: ".plot", Folders:"" },
	}
}
